  var manager, grid;
  $(document).ready(function(){
       
       $("#detailForm").ligerForm();

        function f_initGrid()
        {
            grid = manager = $("#maingrid").ligerGrid({
            columns: [
	            { display: '', name: 'id',hide: true},
	            { display: '', name: 'dept', hide: true},
	            { display: '', name: 'roleId',width:100, hide: true},
	            { display: '姓名', name: 'realName', width: 100,align :"left",type:"string"},
	            { display: '电话', name: 'tel', width: 80,align :"left",type:"string"},
	            { display: '住址', name: 'address', width: 120,align :"left",type:"string"},
	            { display: '邮箱', name: 'email', width: 100,type:"string"},
	            { display: '性别', name: 'sex', width: 30,type:"string"},
	            { display: '民族', name: 'nation', width: 30,type:"string"},    //新增1
	            { display: '出生日期', name: 'birthday', width: 80,type:"string"},
	            { display: '入职时间', name: 'jobInTime', width: 80,type:"string"},
	            { display: '政治面貌', name: 'politics', width: 80,type:"string"},
	            { display: '入党时间', name: 'joinPartyTime', width: 80,type:"string"},  //新增2
	            { display: '排序号', name: 'orderNum', width: 60,type:"string"},
	           	{ display: '用户名', name: 'name', width: 60,align :"left",type:"string"},
	            { display: '角色', name: 'roleStr', width: 100,align :"left",type:"string"},
	            { display: '科室', name: 'deptName', width: 100,align :"left",type:"string"}
            ],

            url: "users/json", 
            method: "GET",                       
            width: '99%',
            height:430,
            rowHeight:'auto',
            toolbar: { items: [
                { text: '增加', click: addRow, icon: 'add' },
                { line: true },
                { text: '修改', click: modifyRow, icon: 'modify' },
                { line: true },
                { text: '删除', click: deleteRow, icon: 'delete' }
                ] }
        	});         	
        }
        
        f_initGrid();
        
        function addRow()
        {
        	showDetail({}, true);
        }
        
        function modifyRow()
        {        	
            var selected = grid.getSelected();
            if (!selected) {
            	$.messager.show("请选择行",false);
            	return;
            }
            var parent = grid.getParent(selected);            
            showDetail(selected, false);
        }
        
        function deleteRow() {
        	f_delete({
        		selected:grid.getSelected(),
        		grid:grid,
        		url:"/user/delete?id="
        	});
        }

	    var detailWin = null, curentData = null
	    var detailForm = $("#detailForm");
	    var v =null;
	    function showDetail(data, isAddNew)
	    { 
	      fromClear("detailForm");
          currentData = data;
          if (detailWin)
          {
            detailWin.show();               
          }
          else
          {
	         	detailWin = $.ligerDialog.open({
	                  target: $("#detail"),
	                  allowClose:false,
	                  width: 700, height: 400, top: 0,
	                  buttons: [
	                  { text: '确定',type:"submit", onclick: function () { $('#detailForm').submit(); } },
	                  { text: '取消', onclick: function () {
	                  	//隐藏错误冒泡提示信息
	              		ligerHideTip();
	                  	detailWin.hide(); } }
	                  ]
	             });
          }
          
          if (currentData){
        	 loadData(currentData);
        	 loadDataSelect("deptCombox",currentData.deptId,currentData.deptName);
        	 loadDataSelect("sex",currentData.sex,currentData.sex);
        	 loadDataCheckBox("roleId",currentData.roleId);
          	 $("[name$=name]").focus();
          }
          
          formSumit({
      		  formId : "detailForm",
      		  url :"/user/add",
      		  grid:grid,
      		  dialog :detailWin,
      		  sumitSuccess :null,
      		  beforeSubmit : null
      	  });
        }
   
	})
        
        function EnterPress(event){             //IE8支持此方法
        if(event.keyCode==13){              //回车键作为执行查询操作
           var name=$("#queryByName").val();  
             $.ajax({
                        loading: '正在查询中...',
                        type: 'POST',
                        url: '/queryjson',                  
                        data: {name:name},
                        success: function (jsondata)
                        {
                            if(jsondata!=null){
                                grid.setOptions({ data: jsondata }); 
                                grid.loadData();  
                                
                            } else{
                                LG.tip("查询无结果!");
                            }                  
                           // LG.tip('保存成功!');
                        },
                        error: function (message)
                        {
                            LG.tip(message);                 
                        }
                    });
        }
    }  
     //根据科室查询
      function EnterPress2(event){             //IE8支持此方法   
        if(event.keyCode==13){              //回车键作为执行查询操作
           var name=$("#queryDeptName").val();  
             $.ajax({
                        loading: '正在查询中...',
                        type: 'POST',
                        url: '/querydeptjson',                  
                        data: {name:name},
                        success: function (jsondata)
                        {
                            if(jsondata!=null){
                                grid.setOptions({ data: jsondata }); 
                                grid.loadData();  
                                
                            } else{
                                LG.tip("查询无结果!");
                            }                  
                           // LG.tip('保存成功!');
                        },
                        error: function (message)
                        {
                            LG.tip(message);                 
                        }
                    });
        }
    }  